<template>
  <div>
<van-nav-bar
  title="账号登录"
  left-arrow
  @click-left="onClickLeft"
/>

<van-form @submit="onSubmit">
  <van-field
    v-model="form.username"
    name="用户名"
    placeholder="请输入账号"
    :rules="[{ required: true, message: '请填写用户名' },{pattern:/^[a-zA-Z0-9_-]{4,16}$/,message:'用户名格式不对'}]"
  />
  <van-field
    v-model="form.password"
    type="password"
    name="密码"
    placeholder="请输入密码"
    :rules="[{ required: true, message: '请填写密码' },{pattern:/^[a-zA-Z0-9_-]{5,12}$/}]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">登 录</van-button>
  </div>
</van-form>

<a href="#/registe">还没有账号，去注册~</a>
  </div>
</template>

<script>
import { Login } from '@/api/My.js'
export default {
  data () {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },

  created () {

  },

  methods: {
    onClickLeft () {
      this.$router.back()
    },
    async onSubmit () {
      try {
        const res = await Login(this.form)
        this.$toast(res.data.description)
      } catch (err) {
        console.log(err.message)
      }
    }
  }
}
</script>

<style scoped lang='less'>
</style>
